import Vue from '@/main.js';

//子级地区信息
export function getcityList(code) {
  var path = `/business/dictionary/queryAreaList?fatherCode=${code}`;
  return Vue.$http.get(path)
    .then((res) => {
      return res.data.data;
    })
    .catch(function (error) {
      console.log(error);
    });
}
export function getAgencySubList(params) { //子级机关列表
  var path = `/business/agency/subList`;
  return Vue.$http.post(path, params)
    .then((res) => {
      return res.data.data;
    })
    .catch(function (error) {
      console.log(error);
    });
}

export function getAgencyList(params) {
  var path = "/business/agency/list";
  return Vue.$http.post(path,params)
    .then((res) => {
      return res.data.data;
    })
    .catch(function (error) {
      console.log(error);
    });
}



export function getFatherAgencies(name) {
  var path = "/business/agency/getFatherAgencies?name=" + name;
  return Vue.$http.get(path)
    .then((res) => {
      return res.data;
    })
    .catch(function (error) {
      console.error(error);
    });
}


export function insertAgency(insertForm) {
  var path = "/business/agency/insert";


  return Vue.$http.post(path, {
    name: insertForm.name,
    pid: insertForm.fatherAgenciesData,
    legalRepresentativeName: insertForm.legalRepresentativeName,
    telephoneNumber: insertForm.telephoneNumber,
    socialCreditCode: insertForm.socialCreditCode,
    type: insertForm.type,
    issuingAuthority: insertForm.issuingAuthority,
    address: insertForm.address,
    criCode: insertForm.criCode,
    issueDate: insertForm.issueDate,
    effectiveStartDate: insertForm.effectiveStartDate,
    effectiveEndDate: insertForm.effectiveEndDate,
    responsiblePersonName: insertForm.responsiblePersonName,
  })
    .then((res) => {
      return res.data;
    })
    .catch(function (error) {
      console.log(error);
    });
}




export function deleteAgencyInformation(id) {
  var path = "/business/agency/delete?id=" + id;
  return Vue.$http.get(path)
    .then((res) => {
      return res.data;
    })
    .catch(function (error) {
      console.log(error);
    });
}



export function getAgencyDetail(id) {
  var path = "/business/agency/detail?id=" + id;
  return Vue.$http.get(path)
    .then((res) => {
      return res.data.data;
    })
    .catch(function (error) {
      console.error(error);
    });
}


export function updateAgencyInfo(insertForm) {
  var path = "/business/agency/update";
  return Vue.$http.post(path, {
    id: insertForm.id,
    name: insertForm.name,
    pid: insertForm.fatherAgenciesData,
    legalRepresentativeName: insertForm.legalRepresentativeName,
    telephoneNumber: insertForm.telephoneNumber,
    socialCreditCode: insertForm.socialCreditCode,
    type: insertForm.type,
    criCode: insertForm.criCode,
    issuingAuthority: insertForm.issuingAuthority,
    address: insertForm.address,
    issueDate: insertForm.issueDate,
    effectiveStartDate: insertForm.effectiveStartDate,
    effectiveEndDate: insertForm.effectiveEndDate,
    responsiblePersonName: insertForm.responsiblePersonName,
  })
    .then((res) => {
      return res.data;
    })
    .catch(function (error) {
      console.log(error);
    });
}


export function getDictionaryList(category) {
  var path = "/business/dictionary/queryList?category=" + category;
  return Vue.$http.get(path)
    .then((res) => {
      return res.data;
    })
    .catch(function (error) {
      console.error(error);
    });
}



export function bindingAU(agencyId, userId) {
  var path = "/business/agency/bindingAU?agencyId=" + agencyId + "&userId=" + userId;
  return Vue.$http.get(path)
    .then((res) => {
      return res.data;
    })
    .catch(function (error) {
      console.error(error);
    });
}

export function unbindingAU(agencyId, userId) {
  var path = "/business/agency/unbindingAU?agencyId=" + agencyId + "&userId=" + userId;
  return Vue.$http.get(path)
    .then((res) => {
      return res.data;
    })
    .catch(function (error) {
      console.error(error);
    });
}


export function getDepartmentHierarchically(agencyId) {
  var path = "/auth/department/getDepartmentListByUnit";
  return Vue.$http.post(path, {
    name: "",
    "unitType": "agency", //必填 单位类型 机关:agency 机构:company
    "unitId": agencyId //对应的机关机构id
  }).then((res) => {
    return res.data;
  })
    .catch(function (error) {
      console.log(error);
    });
}
export function getUserList(params) {
  var path = "/auth/user/getUserList";
  return Vue.$http.post(path, params)
    .then((res) => {
      return res.data.data;
    })
    .catch(function (error) {
      console.log(error);
    });
}
export function mygetUserListForBindingAU(params) { //超级管理员列表 旧版
  var path = "/business/agency/getUserListForBindingAU";
  return Vue.$http.post(path, params)
    .then((res) => {
      return res.data;
    })
    .catch(function (error) {
      console.log(error);
    });
}

export function myGetSuperDetail(userId) { //新版超级管理员 
  var path = `/business/agency/getSuperAdministratorInfo?userId=${userId}`;
  return Vue.$http.get(path)
    .then((res) => {
      return res.data;
    })
    .catch(function (error) {
      console.log(error);
    });
}

export function getPostListByDepId(depId) {
  var path = "/business/agencyPost/getPostListByDepId";
  return Vue.$http.post(path, {
    depId: depId,
  }).then((res) => {
    return res.data;
  })
    .catch(function (error) {
      console.log(error);
    });
}
export function mygetaddUserPost(params) { //给员工添加岗位
  var path = "/business/agencyStaff/addUserPost";
  return Vue.$http.post(path, params).then((res) => {
    return res.data;
  })
    .catch(function (error) {
      console.log(error);
    });
}
export function myupdateUserPost(params) { //修改员工岗位
  var path = "/business/agencyStaff/updateStaff";
  return Vue.$http.post(path, params).then((res) => {
    return res.data;
  })
    .catch(function (error) {
      console.log(error);
    });
}
export function mydeleteUserPost(params) { //删除员工岗位
  var path = "/business/agencyStaff/deleteUserPost";
  return Vue.$http.post(path, params).then((res) => {
    return res.data;
  })
    .catch(function (error) {
      console.log(error);
    });
}

export function addStaff(params) {
  var path = "/business/agencyStaff/addStaff";
  return Vue.$http.post(path, params).then((res) => {
    return res.data;
  })
    .catch(function (error) {
      console.log(error);
    });
}

export function getUserMainStaff(id) { //得到员工主业id(不为0则是有主业)
  var path = "/business/agencyStaff/getUserMainStaff?userId=" + id;
  return Vue.$http.get(path).then((res) => {
    return res.data;
  })
    .catch(function (error) {
      console.log(error);
    });
}


export function getAddedUserList(params) {
  var path = "/business/agencyStaff/addedStaffListByAgencyId";
  return Vue.$http.post(path, params).then((res) => {
    return res.data;
  })
    .catch(function (error) {
      console.log(error);
    });
}

export function deleteStaff(staffId, userId) {
  var path = "/business/agencyStaff/delete?staffId=" + staffId + '&userId=' + userId;
  return Vue.$http.get(path)
    .then((res) => {
      return res.data;
    })
    .catch(function (error) {
      console.error(error);
    });
}

export function getBreadcrumbs(agencyId) {
  var path = "/business/agency/getFatherAgencyData?agencyId=" + agencyId;
  return Vue.$http.get(path)
    .then((res) => {
      return res.data.data;
    })
    .catch(function (error) {
      console.error(error);
    });
}

export function getAgencyStaffDetail(id) {
  var path = `/business/agencyStaff/detail?id=${id}`;
  return Vue.$http.get(path)
    .then((res) => {
      return res.data;
    })
    .catch(function (error) {
      console.error(error);
    });
}



export function updateStaff(id, agencyId, userId, depIds, postIds) {
  var path = "/business/agencyStaff/updateStaff";
  return Vue.$http.post(path, {
    id: id,
    agencyId: agencyId,
    userId: userId,
    depIds: depIds,
    postIds: postIds,
  }).then((res) => {
    return res.data;
  })
    .catch(function (error) {
      console.log(error);
    });
}

